home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Day Cry
/
Day Cry CD.bin
/
oh_towns
/
taropyon
/
splib
/
splib.lzh
/
PRG
/
ZMODEM
/
SZ.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-11
|
45KB
|
2,123 lines
#define __TOWNS__
//#define DEBUG
#define VERSION "3.11 02-26-91"
#define PUBDIR "/usr/spool/uucppublic"
#ifdef __TOWNS__
# define TXBSIZE 16384
# define READCHECK
#endif
/*% cc -compat -M2 -Ox -K -i -DTXBSIZE=16384 -DNFGVMIN -DREADCHECK sz.c -lx -o sz; size sz
<-xtx-*> cc -Osal -DTXBSIZE=32768 -DSV sz.c -lx -o $B/sz; size $B/sz
****************************************************************************
*
* sz.c By Chuck Forsberg, Omen Technology INC
*
****************************************************************************
*
* Typical Unix/Xenix/Clone compiles:
*
* cc -O sz.c -o sz USG (SYS III/V) Unix
* cc -O -DSV sz.c -o sz Sys V Release 2 with non-blocking input
* Define to allow reverse channel checking
* cc -O -DV7 sz.c -o sz Unix Version 7, 2.8 - 4.3 BSD
*
* cc -O -K -i -DNFGVMIN -DREADCHECK sz.c -lx -o sz Classic Xenix
*
* ln sz sb **** All versions ****
* ln sz sx **** All versions ****
*
****************************************************************************
****************************************************************************
*
*
* A program for Unix to send files and commands to computers running
* Professional-YAM, PowerCom, YAM, IMP, or programs supporting Y/XMODEM.
*
* Sz uses buffered I/O to greatly reduce CPU time compared to UMODEM.
*
* USG UNIX (3.0) ioctl conventions courtesy Jeff Martin
*
*
* This version implements numerous enhancements including ZMODEM
* Run Length Encoding and variable length headers. These
* features were not funded by the original Telenet development
* contract.
*
* This software may be freely used for non commercial and
* educational (didactic only) purposes. This software may also
* be freely used to support file transfer operations to or from
* licensed Omen Technology products. Any programs which use
* part or all of this software must be provided in source form
* with this notice intact except by written permission from Omen
* Technology Incorporated.
*
* Use of this software for commercial or administrative purposes
* except when exclusively limited to interfacing Omen Technology
* products requires a per port license payment of $20.00 US per
* port (less in quantity). Use of this code by inclusion,
* decompilation, reverse engineering or any other means
* constitutes agreement to these conditions and acceptance of
* liability to license the materials and payment of reasonable
* legal costs necessary to enforce this license agreement.
*
*
* Omen Technology Inc FAX: 503-621-3745
* Post Office Box 4681
* Portland OR 97208
*
* This code is made available in the hope it will be useful,
* BUT WITHOUT ANY WARRANTY OF ANY KIND OR LIABILITY FOR ANY
* DAMAGES OF ANY KIND.
*/
#ifndef __TOWNS__
char *substr(), *getenv();
#endif
#define LOGFILE "/tmp/szlog"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <stat.h>
#include <setjmp.h>
#include <ctype.h>
#include <errno.h>
#ifdef __TOWNS__
# include <stdarg.h>
# include <process.h>
# include <time.h>
# include <io.h>
# include <splib.h>
# include <fslib.h>
# include "usrlib.h"
# include "rsctrl.h"
# include "flib.h"
# include "msgdat.h"
# ifdef __HIGHC__
# pragma On(Align_labels);
# endif
extern int RsPort;
# define _FSTAT_IGN
#endif
#include "prot.h"
#include "sz.h"
extern int errno;
#define STATIC static
#define HOWMANY 2
STATIC int Zmodem = 0; /* ZMODEM protocol requested by receiver */
unsigned Baudrate = 4800; /* Default, set by first mode() call */
unsigned Effbaud = 4800;
STATIC unsigned Txwindow; /* Control the size of the transmitted window */
STATIC unsigned Txwspac; /* Spacing between zcrcq requests */
STATIC unsigned Txwcnt; /* Counter used to space ack requests */
STATIC long Lrxpos; /* Receiver's last reported offset */
STATIC int errors;
char endmsg[80] = {0}; /* Possible message to display on exit */
#include "rbsb.c" /* most of the system dependent stuff here */
#include "crctab.c"
STATIC int Filesleft;
STATIC long Totalleft;
/*
* Attention string to be executed by receiver to interrupt streaming data
* when an error is detected. A pause (0336) may be needed before the
* ^C (03) or after it.
*/
#ifdef READCHECK
STATIC char Myattn[] = {0};
#else
# ifdef USG
STATIC char Myattn[] = {03, 0336, 0};
# endif
#endif
FILE *in;
char *infile; /* High C stat() */
#ifdef BADSEEK
STATIC int Canseek = 0; /* 1: Can seek 0: only rewind -1: neither (pipe) */
# ifndef TXBSIZE
# define TXBSIZE 16384 /* Must be power of two, < MAXINT */
# endif
#else
STATIC int Canseek = 1; /* 1: Can seek 0: only rewind -1: neither (pipe) */
#endif
#ifdef TXBSIZE
#define TXBMASK (TXBSIZE-1)
STATIC char Txb[TXBSIZE]; /* Circular buffer for file reads */
STATIC char *txbuf = Txb; /* Pointer to current file segment */
#else
STATIC char txbuf[1024];
#endif
STATIC long vpos = 0; /* Number of bytes read from file */
STATIC char Lastrx;
STATIC char Crcflg;
#ifdef DEBUG
STATIC int Verbose = 5;
#else
STATIC int Verbose = 0;
#endif
STATIC int Modem2 = 0; /* XMODEM Protocol - don't send pathnames */
STATIC int Restricted = 0; /* restricted; no /.. or ../ in filenames */
STATIC int Quiet = 0; /* overrides logic that would otherwise set verbose */
STATIC int Ascii = 0; /* Add CR's for brain damaged programs */
STATIC int Fullname = 0; /* transmit full pathname */
STATIC int Unlinkafter = 0; /* Unlink file after it is sent */
STATIC int Dottoslash = 0; /* Change foo.bar.baz to foo/bar/baz */
STATIC int firstsec;
STATIC int errcnt = 0; /* number of files unreadable */
STATIC int blklen = 128; /* length of transmitted records */
STATIC int Optiong; /* Let it rip no wait for sector ACK's */
STATIC int Eofseen; /* EOF seen on input set by zfilbuf */
STATIC int BEofseen; /* EOF seen on input set by fooseek */
STATIC int Totsecs; /* total number of sectors this file */
STATIC int Filcnt = 0; /* count of number of files opened */
STATIC int Lfseen = 0;
STATIC unsigned Rxbuflen = 16384; /* Receiver's max buffer length */
STATIC int Tframlen = 0; /* Override for tx frame length */
STATIC int blkopt = 0; /* Override value for zmodem blklen */
STATIC int Rxflags = 0;
STATIC long bytcnt;
STATIC int Wantfcs32 = TRUE; /* want to send 32 bit FCS */
STATIC char Lzconv; /* Local ZMODEM file conversion request */
STATIC char Lzmanag; /* Local ZMODEM file management request */
STATIC int Lskipnocor;
STATIC char Lztrans;
STATIC int Command; /* Send a command, then exit. */
STATIC char *Cmdstr; /* Pointer to the command string */
STATIC int Cmdtries = 11;
STATIC int Cmdack1; /* Rx ACKs command, then do it */
STATIC int Exitcode;
STATIC int Test = 0; /* 1= Force receiver to send Attn, etc with qbf.
2= Character transparency test */
STATIC char *qbf = "The quick brown fox jumped over the lazy dog's back 1234567890\r\n";
STATIC long Lastsync = 0; /* Last offset to which we got a ZRPOS */
STATIC int Beenhereb4 = 0; /* How many times we've been ZRPOS'd same place */
STATIC jmp_buf tohere; /* For the interrupt on RX timeout */
STATIC jmp_buf intrjmp; /* For the interrupt on RX CAN */
#ifdef XARGSFILE
static char *mystrsave(char *s)
{
register char *p;
char *malloc();
if (p = malloc(strlen(s) + 1))
{
strcpy(p, s);
return p;
}
USR_fprintf(stderr, "No memory for mystrsave!\n");
EXIT(1);
}
/* Remove (presumably) terminating CR and/or LF from string */
static void uncrlf( register char *s )
{
for (; *s; ++s)
switch (*s)
{
case '\r':
case '\n':
*s = 0;
return;
}
}
#endif
#ifdef __TOWNS__
void (*signal_int_func)(int) = SIG_DFL;
extern int CtrlX;
void signal_func(int level)
{
if ( signal_int_func == SIG_ERR )
{
} else if ( signal_int_func == SIG_DFL )
{
EXIT(3);
} else if ( signal_int_fu